package com.baseinfo.service.impl;

import com.baseinfo.service.MessageService;
import com.framework.base.dao.impl.BaseDaoImpl;
import com.model.TMessage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Zhoubin.
 */
@Service
public class MessageServiceImpl implements MessageService{
    @Resource(name="baseDaoImpl")
    BaseDaoImpl baseDao;
    @Override
    public TMessage update (TMessage tMessage) {
        TMessage model = null;
        if (tMessage != null){
            try {
                model = (TMessage) this.baseDao.updatePo(tMessage);
            }catch (Exception e){
                System.out.println("更新启用状态失败");
            }
        }
        return model;
    }

    @Override
    public TMessage findById (Long id) {
        TMessage tMessage = null;
        if(id != null){
            List<Object> params=new ArrayList<Object>();
            StringBuilder hsql = new StringBuilder("from TMessage c where 1=1");
            hsql.append(" and c.id=?");
            params.add(id);
            try{
                tMessage = (TMessage) this.baseDao.getSingleByHsql(hsql.toString(),params);
            }catch (Exception e){
                System.out.println("查找支付方式失败");
            }
        }else{
            System.out.println("短信平台ID为空");
        }
        return tMessage;
    }

    @Override
    public List<TMessage> findAll (Map<String,Object> map) {
        String params="";
        StringBuffer hql=new StringBuffer("from TMessage c where 1=1 and c.isDeleted=0");

        List<TMessage> list=null;
        try{
            list=this.baseDao.listByHql(hql.toString(),null);
        }catch(Exception e){
            e.printStackTrace();
            System.out.println("条件查找短信平台失败");
        }
        return list;
    }

    @Override
    public TMessage saveOrupdate (TMessage tMessage) {
        TMessage model = null;
        if (tMessage != null){
            try {
                model = (TMessage) this.baseDao.saveOrupdate(tMessage);
            }catch (Exception e){
                System.out.println("更新短信平台失败");
            }
        }
        return model;
    }
}
